package com.shenchuangit.webprintclient;

import com.shenchuangit.webprintclient.cycle.AbstractPrintJobHandler;
import com.shenchuangit.webprintclient.print.CustomMediaSize;
import com.shenchuangit.webprintclient.print.PicturePrintTask;
import com.shenchuangit.webprintclient.print.PrintTask;
import com.shenchuangit.webprintclient.util.PrintHelper;

import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.OrientationRequested;
import java.io.File;

public class BarcodePrintJobHandler extends AbstractPrintJobHandler {
    @Override
    public void print(File file) {
        //打印图片路径
//        File file = new File("C:\\Users\\82632\\Desktop\\cnaidc.png");
        //打印机名包含字串
        String printerName = "TSC";

        PrintTask printTask = new PicturePrintTask(DocFlavor.INPUT_STREAM.PNG);
        PrintService printService = PrintHelper.getPrintServiceLikeName(printerName);
        printTask.setPrintService(printService);

        // 设置打印参数
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        aset.add(OrientationRequested.PORTRAIT);
        aset.add(new Copies(1));
        aset.add(new CustomMediaSize(100, 50, Size2DSyntax.MM));
        // aset.add(Finishings.STAPLE);//装订
//            aset.add(Sides.DUPLEX);//单双面
        printTask.print(file, aset);
    }
}
